<template>
  <a-select :placeholder="placeholder" :disabled="disabled" :value="selectValue" @change="handleInput" 
    show-search  
    option-filter-prop="children"
    :filter-option="filterOption"
    allowClear>
    <!-- <a-select-option :value="undefined">请选择</a-select-option> -->
    <a-select-option v-for="(item, key) in dictOptions" :key="key" :value="item.id">
      {{ item.name }}
    </a-select-option>
  </a-select>
</template>

<script>
  import { skStudentList } from '@/api/management.js'

  export default {
    name: "JDictSelectTag",
    props: {
      dictCode: String,
      placeholder: String,
      disabled: Boolean,
      value: [String, Number],
      classId: String,
      firstSelect: Boolean
    },
    data() {
      return {
        dictOptions: [],
        tagType:"select",
        selectValue: undefined
      }
    },
    watch:{
      classId: {
        immediate:true,
        handler() {
          this.initDictData()
        },
      },
      value: {
        handler() {
          this.selectValue = this.value != null ? this.value.toString() : undefined;
        },
      }
    },
    created() {
      //获取字典数据
      this.initDictData();
    },
    computed: {
      // getValueSting(){
      //   // update-begin author:wangshuai date:20200601 for: 不显示placeholder的文字 ------
      //   // 当有null或“” placeholder不显示
      //   return this.value != null ? this.value.toString() : undefined;
      //   // update-end author:wangshuai date:20200601 for: 不显示placeholder的文字 ------
      // },
    },
    methods: {
      initDictData() {
        const params = {
          classId: this.classId == '全园' ? undefined : this.classId
        }
        skStudentList(params).then(res => {
          this.dictOptions = res.result
          if(this.dictOptions.length > 0 && this.firstSelect && this.classId){
            this.selectValue = this.dictOptions[0].id
            this.$emit('change', this.selectValue);
          }
          console.log(this.dictOptions);
        }).catch(error => {
          console.error(error)
        })
      },
      filterOption(input, option) {
        return (
          option.componentOptions.children[0].text.toLowerCase().indexOf(input.toLowerCase()) >= 0
        );
      },
      handleInput(val, option) {
        this.$emit('change', val, option);
        //LOWCOD-2146 【菜单】数据规则，选择自定义SQL 规则值无法输入空格
        this.$emit('input', val, option);
      },
      setCurrentDictOptions(dictOptions){
        this.dictOptions = dictOptions
      },
      getCurrentDictOptions(){
        return this.dictOptions
      }
    },
    model:{
      prop: 'value',
      event: 'change'
    }
  }
</script>

<style scoped>
</style>